var strArray = location.search;
orderStatusAll = strArray.split("?")[1].split("=")[1];


console.log(orderStatusAll);

var goodStr = document.getElementById("goodStr").innerText;

if (orderStatusAll == "410") {
    goodStr = '批量发货';
} else if (orderStatusAll = '492') {
    goodStr = '批量取消';
}
$('#goodStr').html(goodStr);

var newTime = timeAll(); // 定义一个时间戳

// 存储获取到所有orderId拼接
var result = '';




// 获取待发货订单列表
function getWaitShipments() {
    var beginTimeStr = document.getElementById("showDate").innerHTML;
    var endADateStr = document.getElementById("endADate").innerHTML;
    if (beginTimeStr == '选择开始日期') {
        beginTimeStr = '';
    } else {
        beginTimeStr = beginTimeStr.replace('年', '-');
        beginTimeStr = beginTimeStr.replace('月', '-');
        beginTimeStr = beginTimeStr.replace('日', '');
    }

    if (endADateStr == '选择结束日期') {
        endADateStr = '';
    } else {
        endADateStr = endADateStr.replace('年', '-');
        endADateStr = endADateStr.replace('月', '-');
        endADateStr = endADateStr.replace('日', '');
    }

    console.log(beginTimeStr);
    console.log(endADateStr);

    //  拼接，加密，变大写，传值
    var timestamp = 'timeStamp:' + newTime + 'BM' + 'pageNum:' + 1 + 'BM' + 'pageSize:' + 100 + 'BM' + 'startDate:' + beginTimeStr + 'BM' + 'endDate:' + endADateStr + 'BM' + 'orderStatus:' + 400 + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    // 发送请求
    $.ajax({
        type: 'post',
        url: webUrl3 + 'store/paltformTransaction/getOrderList',
        data: {
            'timeStamp': newTime,
            'sign': signs,
            'pageNum': 1,   // 等分页封装好在上传；下拉加载更多
            'pageSize': 100,
            'startDate': beginTimeStr,
            'endDate': endADateStr,
            'orderStatus': 400 // 固定的，只有一个
        },
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data)
            if (data.status == 200) {
                $('#ulList').html(data)
                if (data.data.length > 0) {
                    for (var i = 0; i < data.data.length; i++) {
                        var item=data.data[i];
                        var orderList='<label style="display: flex;border-bottom: 5px solid #F1F1F1 ;line-height: 30px;justify-content: space-between;height: 130px;background: white" for="man">'+
                            '<div style="width: 10%;background: #F1F1F1"><input style="width: 20px;margin-top: 50px;background: red" type="checkbox" value='+item.orderId+' "/></div>'+
                            '<div style="width: 90%">'+
                                '<div style="display: flex;justify-content: space-between">'+
                                    '<div>'+item.dealDate+'</div>'+
                                    '<div>未发货</div>'+
                                '</div>'+
                                '<div style="display: flex;justify-content: space-between">'+
                                    '<div>' +item.productName+ ' </div>'+
                                    '<div>ime:' +item.imei+ '</div>'+
                                '</div>'+

                                '<div>下单时间：' +item.storeCreateDate+ '</div>'+
                                '<div>预估价：' +'￥'+item.dealPrice+ '</div>'+
                            '</div>'+
                        '</label>';
                        $('#ulList').append(orderList)
                    }
                } else {
                    var orderList = '<div style="width: 100%;height: 450px;line-height: 450px;text-align: center">暂时还没有需要发货的订单</div>';
                    $('#ulList').html(orderList);
                }

            } else if (data.status == 300) {
                document.location.href = '../../html/login.html';
            } else {
                alert(data.msg)
            }
        }
    })
}






function checkAll(){
    $(':checkbox').prop('checked',true);
}

function cancleAll() {
    $(':checkbox').prop('checked',false);
}


//1.定义函数 getVal 获取值把prderID 传入到input的value中
function getAllOrderId() {
    result = ''
    //  获取多个ID
    $.each($('input:checkbox'), function () {
        if (this.checked) {
            // 获取都值后；将每一个值后面都加一个逗号；并且拼接起来
            result = result + $(this).val() + ',';
        }
    })
    //  去除拼接就得字符串的最后一位的逗号
    result = result.substr(0, result.length - 1)
    console.log(result);
}

// 批量发货
function GoodClick() {
    getAllOrderId();
    if (result.length>0){
        if (orderStatusAll == "410") {
            document.location.href = '../../sellUpstream/sureGood/sureGood.html?star='+result;
        } else if (orderStatusAll = '492') {
            cancleGoodClick();
        }
    }else {
        dialog("你还没有选择，请先选择")
    }
}



// 批量取消
function cancleGoodClick() {
    console.log(result);
    var timeStamp = "timeStamp:" + newTime + "BM"  + "orderIds:" + result + "BM" + "orderStatus:" + '492' + "BM" ;
    var signs = md5(timeStamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: "post",
        url: webUrl + "paltformTransaction/postBatchDeliveryOrCancle",
        data: {
            "timeStamp": newTime,
            "orderIds": result,
            "orderStatus": '492',
            "sign": signs,
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            if (data.status == 200) {
                gerDiffiendOrder();
            } else if (data.status == 300) {
                document.location.href = '../../html/login.html';
            } else if (data.status == 500) {
                dialog(data.msg);
            }
        },
        error: function (data) {
            //弹出报错内容　　
            dialog("服务器异常")
        }
    })
}
